package Demo01;
import java.util.Arrays;
import  java.util.Comparator;
class Book2{
    private String title;
    private double price;
    public Book2(String title,double price){
        this.title = title;
        this.price = price;
    }
    public String toString(){
        return "【Book】图书名称" + this.title + "图书价格" + this.price + "\n";
    }
    public double getPrice(){
        return this.price;
    }
}
public class Comparator17 {
    public static void main(String[] args) throws Exception {
        Book2 books[] = new Book2[]{
                new Book2("Java从入门到项目实战", 99.8),
                new Book2("Python从入门到项目实战", 99.7),
                new Book2("Go语言从入门到项目实战", 99.3)};
        Comparator<Book2> comparator = (o1, o2) -> {
            if (o1.getPrice() > o1.getPrice()){
                return 1;
            }else if (o1.getPrice() < o1.getPrice()){
                return -1;
            }else{
                return 0;
            }
        };
        Arrays.sort(books,comparator);
        System.out.println(Arrays.toString(books));
    }
}
